unit DUnitX.NUnit.LoggerUI.Solution;
interface
uses MLC.UnitTestFramework, SBD.ServiceProvider;

type
TLoggerFactoryUI = class( TInterfacedObject, ILoggerFactoryUI)
  private
    [Injection('NUnit2.5')] FFactory: ILoggerFactory;
    function  Factory: ILoggerFactory;
    function  EnquireForCreateLogger( out Params: IInterface): boolean;
    procedure ViewEditProperties( const Logger: ITestLogger; Params: IInterface);
  public
    [Configuration] constructor ServiceModeCreate;
  end;

procedure RegisterServices( const Provider: IServiceProvider);

implementation







uses SysUtils, Dialogs, IOUtils;

type
TFilenameFactoryParameter = class( TInterfacedObject, IFilenameFactoryParameter)
  private
    FFileName: string;
    function FileName: string;
    procedure SetFileName( const Value: string);
    function isValidFilename( const Value: string): boolean;
  end;




procedure RegisterServices( const Provider: IServiceProvider);
begin
Provider.RegisterServiceClass( ILoggerFactoryUI, TLoggerFactoryUI)
end;

function TLoggerFactoryUI.EnquireForCreateLogger(
  out Params: IInterface): boolean;
var
  FNParam: IFilenameFactoryParameter;
  AFileName: string;
begin
AFileName := 'NUnit25.log';
result := Dialogs.PromptForFileName( AFileName, 'NUnit log filename?', '.log', 'Title', '', True);
if not result then exit;
AFileName := TPath.GetFullPath( AFileName);
FNParam := TFilenameFactoryParameter.Create;
FNParam.SetFileName( AFileName);
Params := FNParam;
result := FNParam.isValidFilename( AFileName)
end;

function TLoggerFactoryUI.Factory: ILoggerFactory;
begin
result := FFactory
end;

constructor TLoggerFactoryUI.ServiceModeCreate;
begin
end;

procedure TLoggerFactoryUI.ViewEditProperties(
  const Logger: ITestLogger; Params: IInterface);
var
  FNParam: IFilenameFactoryParameter;
  FN: string;
begin
if Supports( Params, IFilenameFactoryParameter, FNParam) then
  FN := FNParam.FileName;
Dialogs.ShowMessageFmt( 'DUnit 2.5 log file is %s', [FN])
end;


function TFilenameFactoryParameter.FileName: string;
begin
result := FFileName
end;

function TFilenameFactoryParameter.isValidFilename(
  const Value: string): boolean;
begin
result := True
end;

procedure TFilenameFactoryParameter.SetFileName( const Value: string);
begin
FFileName := Value
end;

end.
